from PIL import Image
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from Day_2211A.Unit_13.dama import Dama

driver = webdriver.Edge()
driver.maximize_window()
driver.get('http://10.59.9.12:7001/')
# 点击登录
driver.find_element(By.XPATH, '/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
time.sleep(2)
# 定位账号输入框
driver.find_element(By.NAME, 'username').send_keys('15523615757')
# 定位密码输入框
driver.find_element(By.NAME, 'password').send_keys('123456')
time.sleep(2)
dadu = driver.save_screenshot('datu.png')
yzm = driver.find_element(By.XPATH, '//*[@id="theForm"]/div[3]/span[3]/img')
location = yzm.location
size = yzm.size
print(location)
print(size)
left = location['x']
top = location['y']
regit = left + size['width']
bottom = top + size['height']
Image1= Image.open('datu.png')
Image2 = Image1.crop((left*1.5,top*1.5,regit*1.5,bottom*1.5))
Image2.save('image2.png')
print(Image2)
dm = Dama('lj070130', 'lj070130', '970656')
yzmdm = open('image2.png', 'rb').read()
jieguo = dm.PostPic(yzmdm, 1902)
print(jieguo)
result = jieguo['pic_str']
print('我的打码结果：', result)
driver.find_element(By.NAME, 'code').send_keys(result)
time.sleep(2)
driver.find_element(By.CLASS_NAME, 'finish-btn').click()
time.sleep(5)